/**
 * FormInvEmp.java
 * Copyright (C) 2009 Jose Mauro da Silva Sandy
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * FormInvEmp.java
 *
 * Created on 09/05/2009, 13:33:28
 */

package frames;

import java.io.IOException;
import java.util.*;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import negocio.pessoas.*;
import utils.ErrorMessage;

/**
 *
 * @author jmsandy
 */
public class FormInvEmp extends javax.swing.JDialog {

    //<editor-fold defaultstate="collapsed" desc="Fields">
    Pessoa investidor   = null;
    Investidor inv      = null;
    ArrayList lstInv    = null;
    ArrayList lstEmp    = null;
    Hashtable<String, InvestidorEmpreendimento> _lstInv   = null;
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Constructor">
    /** Creates new form FormInvEmp */
    public FormInvEmp() {
        initComponents();
        initializeMyComponents();
    }
    //</editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormInvEmp().setVisible(true);
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lbNomeInvestidor = new javax.swing.JLabel();
        textNomeInvestidor = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        listInvestidor = new javax.swing.JList();
        lbInvestidor = new javax.swing.JLabel();
        lbEmpreendimento = new javax.swing.JLabel();
        panelBotao = new javax.swing.JPanel();
        btnConfirmar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableEmp = new javax.swing.JTable();

        setTitle("Relacionar Investidor ao Empreendimento");
        setName("formInvEmp"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Filtro", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("SansSerif", 0, 12))); // NOI18N
        jPanel1.setFont(new java.awt.Font("SansSerif", 0, 12));

        lbNomeInvestidor.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbNomeInvestidor.setText("Nome do Investidor");

        textNomeInvestidor.setFont(new java.awt.Font("SansSerif", 0, 12));
        textNomeInvestidor.setPreferredSize(new java.awt.Dimension(10, 26));

        btnBuscar.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/lupa.png"))); // NOI18N
        btnBuscar.setToolTipText("Buscar");
        btnBuscar.setBorderPainted(false);
        btnBuscar.setContentAreaFilled(false);
        btnBuscar.setFocusPainted(false);
        btnBuscar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnBuscarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbNomeInvestidor)
                .addGap(18, 18, 18)
                .addComponent(textNomeInvestidor, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(textNomeInvestidor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lbNomeInvestidor, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnBuscar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        listInvestidor.setFont(new java.awt.Font("SansSerif", 0, 12));
        listInvestidor.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listInvestidor.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listInvestidorValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listInvestidor);

        lbInvestidor.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbInvestidor.setText("Investidor");

        lbEmpreendimento.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbEmpreendimento.setText("Empreendimento");

        panelBotao.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, java.awt.Color.gray));
        panelBotao.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        panelBotao.setPreferredSize(new java.awt.Dimension(654, 100));

        btnConfirmar.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
        btnConfirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ok.png"))); // NOI18N
        btnConfirmar.setText("Confirmar");
        btnConfirmar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnConfirmarMouseClicked(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setMaximumSize(new java.awt.Dimension(92, 34));
        btnCancelar.setMinimumSize(new java.awt.Dimension(92, 34));
        btnCancelar.setPreferredSize(new java.awt.Dimension(92, 34));
        btnCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCancelarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout panelBotaoLayout = new javax.swing.GroupLayout(panelBotao);
        panelBotao.setLayout(panelBotaoLayout);
        panelBotaoLayout.setHorizontalGroup(
            panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotaoLayout.createSequentialGroup()
                .addGap(246, 246, 246)
                .addComponent(btnConfirmar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(248, Short.MAX_VALUE))
        );

        panelBotaoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancelar, btnConfirmar});

        panelBotaoLayout.setVerticalGroup(
            panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(btnConfirmar)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelBotaoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnCancelar, btnConfirmar});

        tableEmp.setFont(new java.awt.Font("SansSerif", 0, 12));
        tableEmp.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Selecionado", "Empreendimento"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableEmp.setEnabled(false);
        jScrollPane2.setViewportView(tableEmp);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(panelBotao, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 750, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lbInvestidor)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(12, 12, 12)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 369, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lbEmpreendimento))))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jScrollPane1, jScrollPane2});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbInvestidor, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbEmpreendimento, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotao, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-784)/2, (screenSize.height-403)/2, 784, 403);
    }// </editor-fold>//GEN-END:initComponents

    //<editor-fold defaultstate="collapsed" desc="Events">
    // Busca de investidores
    private void btnBuscarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBuscarMouseClicked
        // TODO add your handling code here:
        // Recupera a lista de investidores
        investidor = new Pessoa();
        lstInv = new ArrayList();

        lstInv = investidor.recLstInvestidoresAtivo(
                             textNomeInvestidor.getText().toUpperCase().trim());

        // Verifica se ocorreu algum erro na busca de investidores
        if(this.investidor.getErrorMessage().equals("")){
            // Caso tenha sido recuperado algum investidor o grid e povoado
            if(lstInv != null && lstInv.size() > 0) mountLstInvestidores();
            else{
                clearFields();
                showMessageWarning(ErrorMessage.MSG_INV_BUSCA);
            }
        }
        else{
            showMessageError(investidor.getErrorMessage());
        }
}//GEN-LAST:event_btnBuscarMouseClicked

    // Mudanca de selecao
    private void listInvestidorValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listInvestidorValueChanged
        // Recebe o indice do registro selecionado e recupera a lista de
        // Investimento x Empreendimento existente
        int selected = listInvestidor.getSelectedIndex();

        if(selected != -1){
            tableEmp.setEnabled(true);

            investidor = new Pessoa();
            investidor = (Pessoa)lstInv.get(selected);

            InvestidorEmpreendimento invEmp = new InvestidorEmpreendimento();
            ArrayList lstAux = new ArrayList();

            inv = new Investidor();
            _lstInv = new Hashtable<String, InvestidorEmpreendimento>();

            inv = inv.recInvestidorPessoa(investidor.getCod_objeto());

            lstAux = invEmp.recLstInvEmp(investidor.getCod_objeto());

            // Verifica se ocorreu algum erro na busca de investidores
            if(invEmp.getErrorMessage().equals("")){

                if(lstAux != null){
                    for(InvestidorEmpreendimento ie :
                                       (ArrayList<InvestidorEmpreendimento>)lstAux){
                        _lstInv.put(ie.getEmpreendimento(), ie);
                    }

                    checkItens();
                }
            }
            else{
                showMessageError(investidor.getErrorMessage());
            }
        }
    }//GEN-LAST:event_listInvestidorValueChanged

    // Realiza o cancelamento fechando o formulario
    private void btnCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelarMouseClicked
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_btnCancelarMouseClicked

    // Confirmacao das mudancas
    private void btnConfirmarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnConfirmarMouseClicked
        verifierRows();
    }//GEN-LAST:event_btnConfirmarMouseClicked

    // Fecha o formulario
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_formWindowClosed
    //</editor-fold>

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConfirmar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbEmpreendimento;
    private javax.swing.JLabel lbInvestidor;
    private javax.swing.JLabel lbNomeInvestidor;
    private javax.swing.JList listInvestidor;
    private javax.swing.JPanel panelBotao;
    private javax.swing.JTable tableEmp;
    private javax.swing.JTextField textNomeInvestidor;
    // End of variables declaration//GEN-END:variables

    //<editor-fold defaultstate="collapsed" desc="Methods">
    // Messagem de erro
    private void showMessageError(String msg){
        JOptionPane.showMessageDialog(this, msg,
         "Relacionar Investidor a Empreendimentos", JOptionPane.ERROR_MESSAGE);
    }

    // Messagem de alerta
    private void showMessageWarning(String msg){
        JOptionPane.showMessageDialog(this, msg,
        "Relacionar Investidor a Empreendimentos", JOptionPane.WARNING_MESSAGE);
    }

    // Inicializa o formulario
    private void clearFields(){
        textNomeInvestidor.setText("");
        textNomeInvestidor.setVisible(true);

        DefaultListModel dlm = new DefaultListModel();
        listInvestidor.removeAll();
        listInvestidor.updateUI();
        listInvestidor.setModel(dlm);

        tableEmp.setEnabled(false);
        for(int i = 0; i < tableEmp.getRowCount(); i++)
            tableEmp.setValueAt(false, i, 0);

        tableEmp.clearSelection();
        tableEmp.updateUI();
    }

    // Monta a lista de insercao de registros
    private void verifierRows(){
        try {
            ArrayList lstAux = new ArrayList();
            ArrayList lstIns = new ArrayList();
            ArrayList lstSel = new ArrayList();
            ArrayList<InvestidorEmpreendimento> lstExc;
            lstExc = new ArrayList<InvestidorEmpreendimento>();

            // Percorre a extensao da tabela e verifica os registros
            lstSel = getListSelected();

            // Realiza uma serie de comparacao para saber quais itens devem ser
            // inseridors
            for(int i = 0; i < lstSel.size(); i++){
                Empreendimento emp = (Empreendimento)
                                             lstEmp.get((Integer)lstSel.get(i));

                lstAux.add(emp.getCod_objeto());

                if(!_lstInv.containsKey(emp.getCod_objeto()))
                    lstIns.add(emp.getCod_objeto());
            }

            // Verifica quais itens devem ser removidos
            for(InvestidorEmpreendimento ie : _lstInv.values()){
                if(!lstAux.contains(ie.getEmpreendimento())) lstExc.add(ie);
            }

            insertLst(lstIns, lstExc);
        } catch (IOException ex) { }
    }

    // Marca como participantes os itens envolvidos
    private void checkItens(){

        // Atualiza a tabela levanco em consideracao os registros recebidos
        for(int i = 0; i < tableEmp.getRowCount(); i++){
            Empreendimento emp = (Empreendimento)lstEmp.get(i);

            if(_lstInv.containsKey(emp.getCod_objeto())){
                tableEmp.setValueAt(true, i, 0);
            }
            else{
                tableEmp.setValueAt(false, i, 0);
            }
        }
    }

    // Atualiza a base de dados
    private void insertLst(ArrayList lstIns, 
                ArrayList<InvestidorEmpreendimento> lstExc) throws IOException{
        ArrayList<InvestidorEmpreendimento> lst;
        lst = new ArrayList<InvestidorEmpreendimento>();

        // Mapeia o objeto para insercao
        for(String ins : (ArrayList<String>)lstIns){
            InvestidorEmpreendimento invEmp = new InvestidorEmpreendimento();
            invEmp.setEmpreendimento(ins);
            invEmp.setInvestidor(inv.getCod_objeto());
            lst.add(invEmp);
        }

        // Mapeia o objeto para remocao
        for(InvestidorEmpreendimento invEmp : lstExc){
            invEmp.setWasDeleted(true);
            lst.add(invEmp);
        }

        InvestidorEmpreendimento ie = new InvestidorEmpreendimento();
        if(ie.atualizarBase(lst)){
            String msg = "Associaç" + (lst.size() > 1 ?
                                                "ões realizadas com sucesso." :
                                                "ão realizada com sucesso.");
            JOptionPane.showMessageDialog(this, msg);
            clearFields();
        }
        else
            showMessageError(ie.getErrorMessage());
    }

    // Pega os registros selecionados na tabela
    private ArrayList getListSelected(){

        ArrayList list = new ArrayList();
        DefaultTableModel def = (DefaultTableModel)tableEmp.getModel();
        for(int i = 0; i < tableEmp.getRowCount(); i++){
            Object select = (Boolean)tableEmp.getValueAt(i, 0);
            if(Boolean.parseBoolean(select.toString())){
                list.add(i);
            }
        }
        return list;
    }

    // Apresenta a lista de investidores recuperada
    private void mountLstInvestidores(){
        // Limpa a lista de investidores
        DefaultListModel dlm = new DefaultListModel();
        listInvestidor.removeAll();
        listInvestidor.updateUI();

        for(Pessoa p : (ArrayList<Pessoa>)lstInv){
            dlm.addElement(p.getNome());
        }

        listInvestidor.setModel(dlm);
    }

    // Povoa o empreendimento
    private void mountLstEmpreendimentos(ArrayList lstAux){
       DefaultTableModel dtm = (DefaultTableModel)tableEmp.getModel();
       tableEmp.removeAll();
       tableEmp.updateUI();

       lstEmp = new ArrayList();

       for(Pessoa p : (ArrayList<Pessoa>)lstAux){
           Object[] row = new Object[]{false, p.getNome()};
           dtm.addRow(row);

           // Cria uma estrutura auxiliar para posterior manipulacao
           Empreendimento emp = new Empreendimento();
           emp = emp.recEmpreendimentoPessoa(p.getCod_objeto());
           lstEmp.add(emp);
       }
    }

    // Inicializa as listas
    private void initializeMyComponents(){
        listInvestidor.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        tableEmp.getColumnModel().getColumn(0).setPreferredWidth(70);
        tableEmp.getColumnModel().getColumn(0).setResizable(false);
        tableEmp.getColumnModel().getColumn(1).setPreferredWidth(290);
        tableEmp.getColumnModel().getColumn(1).setResizable(false);
        tableEmp.getTableHeader().setReorderingAllowed(false);
        tableEmp.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

        // Recupera a lista de empreendimentos
        ArrayList lstAux = new ArrayList();
        Pessoa p = new Pessoa();
        lstAux = p.recLstEmpreendimentosAtivo();
        mountLstEmpreendimentos(lstAux);
    }
    //</editor-fold>
}